#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n, ans=0;
        scanf("%d", &n);
        for (int i=0; i<n; i++) scanf("%d", &a[i]);
        for (int i=0; i<(1<<n); i++) {
            int lastR=-1, lastB=-1, p=0;
            for (int j=0; j<n; j++)
                if ((1<<j) & i) {
                    if (lastR==a[j]) p+=lastR;
                    else lastR = a[j];
                } else {
                    if (lastB==a[j]) p+=lastB;
                    else lastB = a[j];
                }
            ans = max(ans, p);
        }
        printf("%d\n", ans);
    }
    return 0;
}